Combine lines of 2 filesΒΆ
zip(fh1, fh2)
Combine each line from first file with the corresponding line in second file.
with open('abc_colors.txt') as fh1, open('abc_text.txt') as fh2:
for line1, line2 in zip(fh1, fh2):
# line1 from abc_colors.txt, line2 from abc_text.txt
print(line1 + line2)
Output:
Red
Welcome to pyHowTo [in Red].
Green
Welcome to pyHowTo [in Green].
Blue
Welcome to pyHowTo [in Blue].